﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Project
{
    public partial class Frm_TabControl : Form
    {
        public Frm_TabControl()
        {
            InitializeComponent();
            setDGV_Style();
            DataTable dt = new DataTable();
        }

        List<string> lst = new List<string>();
        int index = 0;
        private void Frm_TabControl_Load(object sender, EventArgs e)
        {
            lst.Add("a");
            lst.Add("b");
            lst.Add("c");
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (index + 1 <= lst.Count)
            {
                MessageBox.Show(lst[index]);
                index++;
            }
        }

        /// <summary>
        /// DGV样式.
        /// </summary>
        /// <summary>
        /// DGV样式.
        /// </summary>
        public void setDGV_Style()
        {
            #region DataGridVeiw Style

            dgv.AllowUserToResizeRows = false;
            dgv.ReadOnly = true;
            dgv.MultiSelect = false;

            this.dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
            dgv.ColumnHeadersHeight = 53;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(238, 247, 255);//System.Drawing.Color.LightCyan;

            System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
            dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
            dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(238)))), ((int)(((byte)(247)))), ((int)(((byte)(255)))));
            dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Navy;
            dataGridViewCellStyle2.SelectionBackColor = Color.FromArgb(251, 236, 135);
            dataGridViewCellStyle2.SelectionForeColor = Color.FromArgb(251, 236, 135);



            this.dgv.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
            this.dgv.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;

            //this.dgv.AllowUserToAddRows = true;
            ////this.dgv.AllowUserToDeleteRows = false;
            //this.dgv.BackgroundColor = Color.FromArgb(236, 242, 247);
            ////this.dgv.BorderStyle = System.Windows.Forms.BorderStyle.None;
            //this.dgv.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
            ////this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            //this.dgv.EnableHeadersVisualStyles = false;
            ////this.dgv.GridColor = System.Drawing.SystemColors.GradientInactiveCaption;
            //this.dgv.ReadOnly = false;
            ////this.dgv.RowHeadersVisible = false;




            #endregion
        }

        private void dgv_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics, dgv.ClientRectangle,
               Color.DarkGray, 1, ButtonBorderStyle.Solid,//左
               Color.DarkGray, 1, ButtonBorderStyle.Solid, //上
               Color.DarkGray, 1, ButtonBorderStyle.Solid,//右
               Color.DarkGray, 1, ButtonBorderStyle.Solid);//下
        }

        public void SetCellColor(Color color, DataGridViewRow dr)
        {
            dr.HeaderCell.Style.SelectionBackColor = color;
            dr.HeaderCell.Style.SelectionForeColor = Color.Black;

            foreach (DataGridViewCell item in dr.Cells)
            {
                item.Style.SelectionBackColor = color;
                item.Style.SelectionForeColor = Color.Black;
                if (item.RowIndex % 2 == 0)
                {
                    item.Style.BackColor = Color.White;
                }
                else
                {
                    item.Style.BackColor = Color.FromArgb(238, 247, 255);
                }
            }
        }

        private void dgv_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            SetCellColor(Color.FromArgb(251, 236, 135), dgv.Rows[e.RowIndex]);
        }


        /// <summary>
        /// 读取xml
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public DataTable readXml(string path)
        {
            try
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("cpcode");
                dt.Columns.Add("Date");

                DataSet ds = new DataSet();
                ds.ReadXml(path);

                if (ds != null && ds.Tables.Count > 0 && ds.Tables.Contains("cloudchild"))
                {
                    dt = ds.Tables["cloudchild"];
                }
                return dt;
            }
            catch (Exception)
            {
                throw;
            }

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            f1.ShowInTaskbar = false;
            f1.Show();
        }
    }
}
